package com.example.fileoperate.exception;/*
 * @Auther:hantianbing
 * @Date:2023/7/27
 * @Description:
 */

/**
 * @ClassName ReadFileException
 * @Description
 * @Author hantianbing
 * @Date 2023/7/27 11:32
 **/
public class MyException extends RuntimeException{

    private Enum<? extends  FailCause> cause;

    private Integer code ;

    private String message;

    public MyException(){

    }

    public MyException( String Message){
        super(Message);
    }

    public MyException( String message, Throwable throwable){
        super( message, throwable);
    }

    public MyException(Enum<? extends FailCause> cause){
        this.cause = cause;
        this.code = getCauseCode(cause);
        this.message = getCauseMessage(cause);
    }

    public MyException(Enum<? extends  FailCause> cause, Integer code){
        this.cause = cause;
        this.code = code;
        this.message = getCauseMessage(cause);
    }

    public MyException(Enum<? extends  FailCause> cause, String message){
        this.cause = cause;
        this.code = getCauseCode(cause);
        this.message = message;
    }

    private Integer getCauseCode(Enum<? extends FailCause> cause){
        FailCause failCause = (FailCause) cause;
        return failCause.getCode();
    }

    private String getCauseMessage(Enum<? extends FailCause> cause){
        FailCause failCause = (FailCause) cause;
        return failCause.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
